/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.view;

import com.minierp.bean.BusinessBillBean;
import com.minierp.bean.ReceiveBillBean;
import com.minierp.helper.EncCommonHelper;
import com.minierp.model.BusinessBill;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.Region;
import org.springframework.web.servlet.view.document.AbstractExcelView;

public class BackCostListExcelView extends AbstractExcelView {
	public void buildExcelDocument(Map model, HSSFWorkbook workbook,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		response.reset();
		response.setContentType("APPLICATION/vnd.ms-excel");
		response.setHeader("Content-Disposition",
				"attachment;filename=\"BackCostList.xls\"");
		HSSFFont font = workbook.createFont();
		font.setFontHeightInPoints(10);
		font.setColor(10);
		font.setFontName("黑体");
		font.setBoldweight(700);
		HSSFCellStyle cellStyle = workbook.createCellStyle();
		cellStyle.setFont(font);
		cellStyle.setAlignment(2);
		cellStyle.setBorderBottom(1);
		cellStyle.setWrapText(true);
		cellStyle.setFillForegroundColor(22);
		cellStyle.setFillPattern(1);
		HSSFSheet sheet = workbook.createSheet("list");
		byte rowCount = 0;
		HSSFRow r = sheet.createRow(rowCount);
		HSSFCell c = r.createCell(0);
		r.createCell(1);
		r.createCell(2);
		r.createCell(3);
		r.createCell(4);
		r.createCell(5);
		r.createCell(6);
		r.createCell(7);
		r.createCell(8);
		c.setCellValue(new HSSFRichTextString("回款合计：" + model.get("total")
				+ "（预付：" + model.get("imprestTotal") + "元  结欠："
				+ model.get("receiveTotal") + "元）"));
		sheet.addMergedRegion(new Region(rowCount, 0, rowCount, 8));
		int arg20 = rowCount + 1;
		r = sheet.createRow(arg20);
		c = r.createCell(0);
		r.createCell(1);
		r.createCell(2);
		r.createCell(3);
		r.createCell(4);
		r.createCell(5);
		r.createCell(6);
		r.createCell(7);
		r.createCell(8);
		c.setCellValue(new HSSFRichTextString("预付款"));
		sheet.addMergedRegion(new Region(arg20, 0, arg20, 8));
		++arg20;
		r = sheet.createRow(arg20);
		r.createCell(0).setCellValue(new HSSFRichTextString("预付日期"));
		r.createCell(1).setCellValue(new HSSFRichTextString("业务单号"));
		r.createCell(2).setCellValue(new HSSFRichTextString("付款单位"));
		r.createCell(3).setCellValue(new HSSFRichTextString("摘要"));
		r.createCell(4).setCellValue(new HSSFRichTextString("银行账户"));
		r.createCell(5).setCellValue(new HSSFRichTextString("金额"));
		r.createCell(6).setCellValue(new HSSFRichTextString("经办人"));
		r.createCell(7).setCellValue(new HSSFRichTextString("开单人"));
		r.createCell(8).setCellValue(new HSSFRichTextString("部门"));
		++arg20;
		SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
		List imprestList = (List) model.get("imprestList");
		List bankAccountList = (List) model.get("bankAccountList");
		if (imprestList != null) {
			for (int b = 0; b < imprestList.size(); ++b) {
				Object[] receiveList = (Object[]) imprestList.get(b);
				BusinessBillBean bean = (BusinessBillBean) receiveList[0];
				BusinessBill p = bean.getBusinessBill();
				String os = (String) receiveList[1];
				if (p.getLinkman() != null && !p.getLinkman().equals("")) {
					os = os + "(" + p.getLinkman() + ")";
				}

				r = sheet.createRow(arg20);
				r.createCell(0).setCellValue(
						new HSSFRichTextString(sf.format(p.getOrderDate())));
				r.createCell(1).setCellValue(
						new HSSFRichTextString(p.getBillCode()));
				r.createCell(2).setCellValue(new HSSFRichTextString(os));
				r.createCell(3).setCellValue(
						new HSSFRichTextString(p.getContent()));
				r.createCell(4).setCellValue(
						new HSSFRichTextString(EncCommonHelper
								.getSimpleObjectName(bankAccountList,
										p.getBankAccountId())));
				r.createCell(5).setCellValue(p.getImprest().doubleValue());
				r.createCell(6).setCellValue(
						new HSSFRichTextString(p.getManagerName()));
				r.createCell(7).setCellValue(
						new HSSFRichTextString(p.getCreaterName()));
				r.createCell(8).setCellValue(
						new HSSFRichTextString(bean.getDepartmentName()));
				++arg20;
			}
		}

		r = sheet.createRow(arg20);
		c = r.createCell(0);
		r.createCell(1);
		r.createCell(2);
		r.createCell(3);
		r.createCell(4);
		r.createCell(5);
		r.createCell(6);
		r.createCell(7);
		r.createCell(8);
		c.setCellValue(new HSSFRichTextString("付款"));
		sheet.addMergedRegion(new Region(arg20, 0, arg20, 8));
		++arg20;
		r = sheet.createRow(arg20);
		r.createCell(0).setCellValue(new HSSFRichTextString("回款日期"));
		r.createCell(1).setCellValue(new HSSFRichTextString("收款单号"));
		r.createCell(2).setCellValue(new HSSFRichTextString("付款单位"));
		r.createCell(3).setCellValue(new HSSFRichTextString("摘要"));
		r.createCell(4).setCellValue(new HSSFRichTextString("银行账户"));
		r.createCell(5).setCellValue(new HSSFRichTextString("金额"));
		r.createCell(6).setCellValue(new HSSFRichTextString("经办人"));
		r.createCell(7).setCellValue(new HSSFRichTextString("开单人"));
		r.createCell(8).setCellValue(new HSSFRichTextString("部门"));
		++arg20;
		List arg22 = (List) model.get("receiveList");
		if (arg22 != null) {
			for (int arg23 = 0; arg23 < arg22.size(); ++arg23) {
				Object[] objs = (Object[]) arg22.get(arg23);
				ReceiveBillBean arg21 = (ReceiveBillBean) objs[0];
				String estName = (String) objs[1];
				r = sheet.createRow(arg20);
				r.createCell(0).setCellValue(
						new HSSFRichTextString(sf.format(arg21.getReceiveBill()
								.getReceiveDate())));
				r.createCell(1).setCellValue(
						new HSSFRichTextString(arg21.getReceiveBill()
								.getBillCode()));
				r.createCell(2).setCellValue(new HSSFRichTextString(estName));
				r.createCell(3).setCellValue(
						new HSSFRichTextString(arg21.getReceiveBill()
								.getDescription()));
				r.createCell(4).setCellValue(
						new HSSFRichTextString(EncCommonHelper
								.getSimpleObjectName(bankAccountList, arg21
										.getReceiveBill().getBankAccountId())));
				r.createCell(5).setCellValue(
						arg21.getReceiveBill().getCost().doubleValue());
				r.createCell(6).setCellValue(
						new HSSFRichTextString(arg21.getReceiveBill()
								.getManagerName()));
				r.createCell(7).setCellValue(
						new HSSFRichTextString(arg21.getReceiveBill()
								.getCreaterName()));
				r.createCell(8).setCellValue(
						new HSSFRichTextString(arg21.getDepartmentName()));
				++arg20;
			}
		}

		ServletOutputStream arg24 = response.getOutputStream();
		workbook.write(arg24);
		arg24.flush();
		arg24.close();
	}
}